package ProductofArrayExceptSelf;


public class Solution {
    public int[] productExceptSelf(int[] nums) {
        int[] left=new int[nums.length];
        int[] right=new int[nums.length];
        left[0]=nums[0];
        right[nums.length-1]=nums[nums.length-1];
        for (int i=1;i<=nums.length-1;i++)
        	left[i]=left[i-1]*nums[i];
        for (int i=nums.length-2;i>=0;i--)
        	right[i]=right[i+1]*nums[i];
        nums[0]=left[nums.length-1];
        nums[nums.length-1]=right[0];
        for (int i=1;i<=nums.length-2;i++)
        	nums[i]=left[i-1]*right[i+1];
        nums[0]=right[1];
        nums[nums.length-1]=left[nums.length-2];
        return nums;
    }
    public static void main(String args[]) {
    	int[] nums={1,2,3,4};
    	Solution so=new Solution();
    	so.productExceptSelf(nums);
    	for (int i=0;i<nums.length;i++)
    		System.out.println(nums[i]);
		
	}
}
